Immune predictions correlated with multiplier latent variable expression

First we get the LV multiplier values from the nf-lv-viz repo and deconvolution predictions from Synapse

#get immune predictions
dtab<-synapser::synTableQuery(paste('select * from',deconv_scores))$asDataFrame()%>%
  rename(immScore='score')

##get latent variable scores
mp_res<-synTableQuery("SELECT * FROM syn21046991")$filepath %>% 
  readr::read_csv() %>% 
  filter(!is.na(tumorType),
         !grepl('xenograft', specimenID, ignore.case = T),
         !specimenID %in% c("BI386-004","CW225-001","DW356-002",
                            "JK368-003", "SK436-005"))
## Parsed with column specification:
## cols(
##   .default = col_character(),
##   ROW_ID = col_double(),
##   ROW_VERSION = col_double(),
##   value = col_double(),
##   isCellLine = col_logical()
## )
## See spec(...) for full column specifications.
dtab<-subset(dtab,method!='xcell')

combined=dtab%>%select(c(cell_type,method,specimenID,immScore))%>%
  left_join(mp_res,by='specimenID')

Then we can compute the correlation of each cell type measurement with each protein

corVals=combined%>%group_by(cell_type,latent_var,method)%>%summarize(corVal=cor(immScore,value,method = "spearman"))

DT::datatable(corVals)

Plotting LV correlations

We are interested in particular protein signaling activity that might give rise to specific immune phonetypes.

##now how do we bracket them?
##plot correlation distributions by cell type and method. 
require(ggplot2)
p<-ggplot(corVals)+geom_boxplot(aes(x=cell_type,y=corVal,fill=method))+ theme(axis.text.x = element_text(angle = 45, hjust = 1))+ggtitle("Correlation of MultiPLIER Latent Variables with predicted cell type")
print(p)

There are some latent variables that show up as highly correlated. By choosing a threshold, we can evaluate what they are in more detail.

corthresh=0.6

##now filter to the cell types with correlated latent variables (or anticorrelated)
cor_cell_types=subset(corVals,abs(corVal)>corthresh)%>%
  ungroup()%>%
  group_by(latent_var)%>%
  mutate(numTypes=n_distinct(cell_type))%>%
  subset(numTypes>1)%>%
  mutate(cell_types=paste(unique(cell_type),collapse=','))%>%
  ungroup()%>%
  select(latent_var,method,cell_types)%>%unique()
print(paste('we found',nrow(cor_cell_types),'latent variables/methods with some cell types with correlation greater than',corthresh))
## [1] "we found 84 latent variables/methods with some cell types with correlation greater than 0.6"
DT::datatable(cor_cell_types)

Plots of LVs with correlated immune cell types

Here we iterate through each of the LVs with correlated immune cell types and plot

Cibersort-correlated cell types

First we plot the cibersort

apply(subset(cor_cell_types,method=='cibersort'),1,function(x){
  ct=x[['latent_var']]
  m=x[['method']]

cat(ct)
  #for each gene and cell type
  lvs=subset(corVals,latent_var==ct)%>%
        subset(abs(corVal)>corthresh)%>%
    subset(method==m)%>%arrange(desc(corVal))%>%
      ungroup()

    if(nrow(lvs)>12){
    new.corthresh=format(lvs$corVal[15],digits=3)
    lvs=lvs[1:12,]
  }else{
    new.corthresh=corthresh
  }

  scores=subset(combined,cell_type%in%lvs$cell_type)%>%
      subset(latent_var==ct)%>%
      subset(method==m)

  p2<- ggplot(scores %>% mutate(latent_var = stringr::str_trunc(latent_var, 30)))+
      geom_point(aes(x=immScore,y=value,
          col=cell_type,shape=tumorType))+
  #  scale_x_log10()+
      ggtitle(paste(m,'predictions of',ct,'correlation >',new.corthresh))
  print(p2)
})
## LV 192

## LV 209

## LV 245

## LV 252

## LV 282

## LV 327

## LV 423

## LV 546

## LV 618

## LV 689

## 447,KEGG_LYSOSOME

## 82,PID_RAC1_PATHWAY

## LV 326

## LV 624

## LV 615

## [[1]]

## 
## [[2]]

## 
## [[3]]

## 
## [[4]]

## 
## [[5]]

## 
## [[6]]

## 
## [[7]]

## 
## [[8]]

## 
## [[9]]

## 
## [[10]]

## 
## [[11]]

## 
## [[12]]

## 
## [[13]]

## 
## [[14]]

## 
## [[15]]

MCPCOUNTER-correlated cell types

First we plot the mcp-counter

apply(subset(cor_cell_types,method=='mcp_counter'),1,function(x){
  ct=x[['latent_var']]
  m=x[['method']]

cat(ct)
  #for each gene and cell type
  lvs=subset(corVals,latent_var==ct)%>%
        subset(abs(corVal)>corthresh)%>%
    subset(method==m)%>%arrange(desc(corVal))%>%
      ungroup()

    if(nrow(lvs)>12){
    new.corthresh=format(lvs$corVal[15],digits=3)
    lvs=lvs[1:12,]
  }else{
    new.corthresh=corthresh
  }

  scores=subset(combined,cell_type%in%lvs$cell_type)%>%
      subset(latent_var==ct)%>%
      subset(method==m)

  p2<- ggplot(scores %>% mutate(latent_var = stringr::str_trunc(latent_var, 30)))+
      geom_point(aes(x=immScore,y=value,
          col=cell_type,shape=tumorType))+
    scale_x_log10()+
      ggtitle(paste(m,'predictions of',ct,'correlation >',new.corthresh))
  print(p2)
})
## LV 130

## LV 174

## LV 222

## LV 349

## LV 381

## LV 448

## LV 584

## LV 621

## LV 703

## LV 748

## LV 757

## LV 940

## LV 252

## LV 327

## LV 540

## 171,KEGG_FATTY_ACID_METABOLISM

## LV 768

## 124,REACTOME_NFKB_AND_MAP_KINASES_ACTIVATION_MEDIATED_BY_TLR4_SIGNALING_REPERTOIRE

## 140,REACTOME_INTERFERON_GAMMA_SIGNALING

## 447,KEGG_LYSOSOME

## 82,PID_RAC1_PATHWAY

## LV 112

## LV 128

## LV 141

## LV 153

## LV 182

## LV 224

## LV 229

## LV 231

## LV 248

## LV 256

## LV 282

## LV 287

## LV 305

## LV 326

## LV 338

## LV 369

## LV 377

## LV 392

## LV 393

## LV 40

## LV 421

## LV 430

## LV 487

## LV 495

## LV 5

## LV 500

## LV 531

## LV 553

## LV 559

## LV 569

## LV 575

## LV 585

## LV 589

## LV 607

## LV 608

## LV 616

## LV 643

## LV 644

## LV 677

## LV 709

## LV 784

## LV 79

## LV 812

## LV 817

## LV 83

## LV 904

## LV 936

## LV 966

## [[1]]

## 
## [[2]]

## 
## [[3]]

## 
## [[4]]

## 
## [[5]]

## 
## [[6]]

## 
## [[7]]

## 
## [[8]]

## 
## [[9]]

## 
## [[10]]

## 
## [[11]]

## 
## [[12]]

## 
## [[13]]

## 
## [[14]]

## 
## [[15]]

## 
## [[16]]

## 
## [[17]]

## 
## [[18]]

## 
## [[19]]

## 
## [[20]]

## 
## [[21]]

## 
## [[22]]

## 
## [[23]]

## 
## [[24]]

## 
## [[25]]

## 
## [[26]]

## 
## [[27]]

## 
## [[28]]

## 
## [[29]]

## 
## [[30]]

## 
## [[31]]

## 
## [[32]]

## 
## [[33]]

## 
## [[34]]

## 
## [[35]]

## 
## [[36]]

## 
## [[37]]

## 
## [[38]]

## 
## [[39]]

## 
## [[40]]

## 
## [[41]]

## 
## [[42]]

## 
## [[43]]

## 
## [[44]]

## 
## [[45]]

## 
## [[46]]

## 
## [[47]]

## 
## [[48]]

## 
## [[49]]

## 
## [[50]]

## 
## [[51]]

## 
## [[52]]

## 
## [[53]]

## 
## [[54]]

## 
## [[55]]

## 
## [[56]]

## 
## [[57]]

## 
## [[58]]

## 
## [[59]]

## 
## [[60]]

## 
## [[61]]

## 
## [[62]]

## 
## [[63]]

## 
## [[64]]

## 
## [[65]]

## 
## [[66]]

## 
## [[67]]

## 
## [[68]]

## 
## [[69]]